﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GMS.Model;
using GMS.Utils;
using GMS.Web.CommonPage;

/// <summary>
/// ManageControls 的摘要说明
/// </summary>
public class ManageControls
{

    public ManageControls()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public static string style_tab = "",
                         style_tr = "",
                         style_td = "";



    private string columnsString = string.Empty;

    public string DisplayTitle(Dictionary<string, TabColumns> tabColumns, DataTable dt, List<string> approvalCon)
    {
        return DisplayTitleWithNoOperation(tabColumns, dt, approvalCon, true);
    }

    public string DisplayTitleWithNoOperation(Dictionary<string, TabColumns> tabColumns, DataTable dt, List<string> approvalCon, bool hasCheck)
    {
        columnsString = ",";
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            if (tabColumns.ContainsKey(dt.Columns[i].Caption.ToUpper()))
            {
                if (tabColumns[dt.Columns[i].Caption].COLSHOWED == 1)
                {
                    //sHtmlControls += "<td class='tdDataInfo'><span style=\"text-align:center; cursor:pointer; \" onmousemove=\"change_Style_Mouse_Move(this);\" onmouseout=\"change_Style_Mouse_Out(this);\" onclick='SortCol(\"" + tabColumns[dt.Columns[i].Caption].COLNAME + "\");'><nobr>" + tabColumns[dt.Columns[i].Caption].COLNAME + "</nobr></span></td>";
                    columnsString += dt.Columns[i].Caption.ToUpper() + ",";
                }
            }
        }

        string sHtmlControls = string.Empty;
        string[] colHtmls = TableUtility.ToColumnHtml(tabColumns, dt);
        if (colHtmls.Length > 0)
        {
            sHtmlControls = "<tr style='font-weight:bold;' class='trTitle'>";
            if (hasCheck)
            {
                sHtmlControls += "<td rowspan='" + colHtmls.Length + "' class='tdSelAll' style='text-align:left' ><input name=\"chk_all\" type=\"checkbox\" onclick=\"CheckAll(this,'chk_item');\" /></td>";
            }
            sHtmlControls += "<td rowspan='" + colHtmls.Length + "' class='tdDataInfo' ><nobr>序号</nobr></td>";
            sHtmlControls += colHtmls[0];

            //审核约束标题解析
            if (approvalCon != null && approvalCon.Count > 0)
            {
                foreach (string con in approvalCon)
                {
                    sHtmlControls += "<td rowspan='" + colHtmls.Length + "' class='tdDataInfo'>" + con + "</td>";
                }
            }

            //去掉详情删除链接
            //sHtmlControls += "<td class='tdDetails'><span>详情</span></td>";
            //sHtmlControls += "<td class='tdDel'><span>删除</span></td>";
            sHtmlControls += "</tr>";

            for (int i = 1; i < colHtmls.Length; i++)
            {
                sHtmlControls += "<tr style='font-weight:bold;' class='trTitle'>";
                sHtmlControls += colHtmls[i];
                sHtmlControls += "</tr>";
            }
        }

        return sHtmlControls;
    }


    public string DisplayColumnIndexs()
    {
        return columnsString;
    }



    /*
     * 1——整型Integer，
     * 2——浮点型Float，
     * 3——字符型String，
     * 4——布尔Bool，
     * 5——Date，
     * 6——time， 
     * 7——Binary/Image
     */

    /// <summary>
    /// 详情中显示数据自动生成个组建脚本
    /// </summary>
    /// <param name="MainType"></param>
    /// <param name="iControlsType"></param>
    /// <param name="bRead"></param>
    /// <param name="sId"></param>
    /// <param name="sCaption"></param>
    /// <param name="sValue"></param>
    /// <param name="dtSelected"></param>
    /// <param name="sFatherValue"></param>
    /// <param name="dtId"></param>
    /// <param name="dtName"></param>
    /// <param name="maxlength"></param>
    /// <returns></returns>
    public string DisplayDetails(int MainType,int iControlsType, Boolean bRead, string sId, string sCaption, string sValue, DataTable dtSelected,string sFatherValue, string dtId, string dtName, string maxlength)
    {
        string sHtmlControls = string.Empty;
        string strTemp = string.Empty;
        string selSelected = string.Empty;
        string sMainType = string.Empty;
        string sComID = "Cls" + sId;
        string sCaptionTypeS = "<td>";
        string sCaptionTypeE = "</td>";
        string sConTypeS = "<td>";
        string sConTypeE = "</td>";

        switch (MainType)
        {
            case 0:
                {
                    sCaptionTypeS = "<td>";
                    sCaptionTypeE = "</td>";
                    sConTypeS = "<td>";
                    sConTypeE = "</td>";
                    break;
                }
            case 1:
                {
                    sCaptionTypeS = "<div>";
                    sCaptionTypeE = "</div>";
                    sConTypeS = "<div>";
                    sConTypeE = "</div>";
                    break;
                }
            default:
                {
                    sCaptionTypeS = "<td>";
                    sCaptionTypeE = "</td>";
                    sConTypeS = "<td>";
                    sConTypeE = "</td>";
                    break;
                }
        }
        sHtmlControls = sCaptionTypeS + sCaption + sCaptionTypeE;
        sHtmlControls += sConTypeS;

        if (bRead && (iControlsType >= (int)EnumHelper.E_ColDataType.COL_AUTOID //只读并且不是关联的数据 不用编辑框显示
            && iControlsType <= (int)EnumHelper.E_ColDataType.COL_BINARY))
        {
            sHtmlControls += sValue + "<input id=\"" + sComID + "\" name =\"" + sComID + "\" type=\"hidden\" value=\"" + sValue + "\" />";
            sHtmlControls += sConTypeE;
            return sHtmlControls;
        }

        switch (iControlsType)
        {
            case (int)EnumHelper.E_ColDataType.COL_AUTOID: //自增、不可修改的
                {
                    sHtmlControls += sValue;
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_INT: //整型Integer
                {
                    sHtmlControls += "<input id=\"" + sComID+ "\" name =\"" + sComID+ "\" type=\"text\" runat=\"server\" value=\"" + sValue + "\" maxlength=\"27\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += " onblur=\"CheckInt(this)\" />";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_FLOAT: //浮点型Float，
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" type=\"text\" runat=\"server\" value=\"" + sValue + "\" maxlength=\"27\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += " onblur=\"CheckFloat(this)\" />";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_STRING: //字符型String，
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" type=\"text\" runat=\"server\" value=\"" + sValue + "\" maxlength=\"" + maxlength + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += " />";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_BOOL://下拉框 bool
                {
                    sHtmlControls += "<select id=\"" + sComID + "\" name =\"" + sComID + "\"> ";
                    //第一行为空，即未选中
                    sHtmlControls += "<option value=\"\"></option>";

                    sHtmlControls += "<option value = \"1\"";
                    if (sValue.Trim() == "1")   //一定要有trim()，因为数据库里面字段是2个字符，可能有空格的
                        sHtmlControls += " selected=\"selected\" ";
                    sHtmlControls += ">是</option>";
                    sHtmlControls += "<option value = \"2\" ";
                    if (sValue.Trim() == "2")
                        sHtmlControls += " selected=\"selected\" ";
                    sHtmlControls += " >否</option>";
                    sHtmlControls += "</select>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_DATE://Date
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "  onfocus=\"setday(this)\" ";
                    sHtmlControls += "/>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_TIME://time
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "/>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_IMAGE://Binary/Image
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "/>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_BINARY:
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "/>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_DDL://下拉框
                {
                    if (bRead)
                    {
                        if (sValue.Equals(""))
                        {
                            sHtmlControls += "";
                        }
                        else
                        {
                            for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                            {
                                string showStr = "";
                                if (dtSelected.Rows[i][dtId].ToString() == sValue)
                                {
                                    showStr = dtSelected.Rows[i][dtName].ToString(); /*dtSelected.Rows[i][dtId].ToString() + " " + */
                                    sHtmlControls += showStr + "<input id=\"" + sComID + "\" name =\"" + 
                                        sComID + "\" type=\"hidden\" value=\"" + sValue + "\" />";
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        sHtmlControls += "<select id=\"" + sComID+ "\" name =\"" + sComID+ "\"> ";
                        //第一行为空，即未选中
                        sHtmlControls += "<option value=\"\"></option>";
                        if ((dtSelected != null)&&((sFatherValue == null)||(sFatherValue.Length<=0)))
                        {
                            for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                            {
                                sHtmlControls += "<option value=\"" + dtSelected.Rows[i][dtId].ToString() + "\" ";
                                if (dtSelected.Rows[i][dtId].ToString() == sValue)
                                    sHtmlControls += " selected=\"selected\" ";
                                sHtmlControls += ">" + /*dtSelected.Rows[i][dtId].ToString() + " "  + */dtSelected.Rows[i][dtName].ToString() + "</option>";
                            }
                        }
                        else if ((dtSelected != null) && (sFatherValue != null)&&(sFatherValue.Length >0))//子级时显示数据
                        {
                            for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                            {
                                if (dtSelected.Rows[i]["Father_PropertyValue"].ToString().Equals(sFatherValue))
                                {
                                sHtmlControls += "<option value=\"" + dtSelected.Rows[i][dtId].ToString() + "\" ";
                                if (dtSelected.Rows[i][dtId].ToString() == sValue)
                                    sHtmlControls += " selected=\"selected\" ";
                                sHtmlControls += ">" + /*dtSelected.Rows[i][dtId].ToString() + " " + */dtSelected.Rows[i][dtName].ToString() + "</option>";
                                }
                            }
                        }
                        else //子级时显示数据
                        {
                            sHtmlControls += "<option value=\"-1\" ";
                            sHtmlControls += "></option>";
                        }
                        sHtmlControls += "</select>";
                    }
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_FDDL://多级下拉框实现 aiks 20090927
                {
                    string strFValue = string.Empty;
                    string strChldValue = string.Empty;
                    string sAllChldValue = string.Empty;
                    string strFName = string.Empty;
                    string strChldName = string.Empty;
                    string sAllChldName = string.Empty;
                    strTemp = string.Empty;
                    string fid = "Father_PropertyValue";
                    string fname = "TypeName";
                    string dtTableName =dtSelected.TableName;
                    string sChildControls = dtTableName.Substring(dtTableName.IndexOf("-")+1, dtTableName.Length - dtTableName.IndexOf("-")-1);
                    for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                    {
                        if (dtSelected.Rows[i][fid].ToString() != strFValue)
                        {
                            if (strFValue != "")
                            {
                                sAllChldValue += strFValue + strChldValue + ";";
                                sAllChldName += strFValue + strChldName + ";";
                                strChldValue = "";
                                strChldName = "";
                            }
                            strFValue = dtSelected.Rows[i][fid].ToString();
                            strTemp += "<option value=\"" + strFValue + "\" ";
                            if (strFValue == sValue)
                                strTemp += " selected=\"selected\" ";
                            strTemp += ">" + /*strFValue + " " + */dtSelected.Rows[i][fname].ToString() + "</option>";
                            strChldValue += "-" + dtSelected.Rows[i][dtId].ToString();
                            strChldName += "-" + dtSelected.Rows[i][dtName].ToString();
                        }
                        else
                        {
                            strChldValue += "-" + dtSelected.Rows[i][dtId].ToString();
                            strChldName += "-" + dtSelected.Rows[i][dtName].ToString();
                        }
                    }

                    sAllChldValue += strFValue + strChldValue + ";";
                    sAllChldName += strFValue + strChldName + ";";
                    sHtmlControls += "<select id=\"" + sComID+ "\" name =\"" + sComID+ "\" OnChange=\"SelectTheSecond(this,\"Cls" + sChildControls
                                        + "\",\"" + sAllChldValue + "\")\"> ";//,\"" + sAllChldName + "\"
                    
                    //第一行为空，即未选中
                    sHtmlControls += "<option value=\"\"></option>";
                    sHtmlControls += strTemp;
                    sHtmlControls += "</select>";
                    sHtmlControls += "<input id=\"ChildCls" + sChildControls + "\" name =\"ChildCls" + sChildControls + "\" "
                                        + " type=\"hidden\" value=\"" + sAllChldName + "\" />";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_TEXTAREA://textarea
                {
                    bRead = false;
                    sHtmlControls += "<asp:TextBox ID=\"" + sId + "\" runat=\"server\" TextMode=\"MultiLine\" Text=\""
                                    + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "ReadOnly=\"true\" ";
                    sHtmlControls += "></asp:TextBox>";
                    break;
                }
            default:
                {
                    sHtmlControls += "<input id=\"" + sComID+ "\" name =\"" + sComID+ "\" "
                                        + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += " />";
                    break;
                }

        }
        sHtmlControls += sConTypeE;
        return sHtmlControls;
    }

    //aiks 20091007 查询条件控件自动生成
    public string DisplayQuerys(int iControlsType, Boolean bRead, string sId, string sCaption, string sValue, DataTable dtSelected,string sFatherValue,string dtId,string dtName)
    {
        string sHtmlControls = string.Empty;
        string sComID = "Cls-"+sId+"-"+iControlsType.ToString();
        string sCaptionTypeS = "<td>";
        string sCaptionTypeE = "</td>";
        string sConTypeS = "<td>";
        string sConTypeE = "</td>";

        //
        sHtmlControls = sCaptionTypeS + sCaption + sCaptionTypeE;
        sHtmlControls += sConTypeS;
        switch (iControlsType)
        {
            case (int)EnumHelper.E_ColDataType.COL_AUTOID://字符型控件生成 text
            case (int)EnumHelper.E_ColDataType.COL_FLOAT://字符型控件生成 text
            case (int)EnumHelper.E_ColDataType.COL_INT://字符型控件生成 text
            case (int)EnumHelper.E_ColDataType.COL_STRING://字符型控件生成 text
                {
                    sHtmlControls +="<input id=\"" + sComID+ "\" name =\"" + sComID+ "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"true\" ";
                    sHtmlControls += "/>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_DATE:
                {

                    sHtmlControls = sCaptionTypeS + sCaption + "开始" + sCaptionTypeE;
                    sHtmlControls += sConTypeS;
                    sHtmlControls += "<input id=\"S_" + sComID + "\" name =\"S_" + sComID + "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "  onfocus=\"setday(this)\" ";
                    sHtmlControls += "/>";
                    sHtmlControls += sConTypeE;
                    sHtmlControls += sCaptionTypeS + sCaption + "结束" + sCaptionTypeE;
                    sHtmlControls += sConTypeS;
                    sHtmlControls += "<input id=\"E_" + sComID + "\" name =\"E_" + sComID + "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "  onfocus=\"setday(this)\" ";
                    sHtmlControls += "/>";
                    break;
                }
            case 4://多选条件选项
                {
                    sHtmlControls += "<input id=\"" + sComID+ "\" name =\"" + sComID+ "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" onclick=javascript:toExit('show','boysoft')";
                    //if (bRead)
                    //    sHtmlControls += "readonly=\"true\" ";
                    sHtmlControls += "/>";
                    sHtmlControls += "<table class=\"cssCheckList\" id =\"boysoft\">";
                    for (int i = 0; i < dtSelected.Rows.Count - 1; ++i)
                    {
                        sHtmlControls += "<tr><td nowrap ><input type=\"checkbox\" name=\"cb" + sId + "\" value=\"v" + i.ToString() + "\">" + dtSelected.Rows[i][dtName].ToString() + "</td></tr>";
                    }
                    sHtmlControls += "</table>";
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_DDL://下拉框 select
                {
                    if (bRead)  //直接显示，没有任何控件支持；
                    {
                        for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                        {
                            string showStr = "";
                            if (dtSelected.Rows[i][dtId].ToString() == sValue)
                            {
                                showStr = dtSelected.Rows[i][dtId].ToString() + " " + dtSelected.Rows[i][dtName].ToString();
                                sHtmlControls += showStr;               
                                break;
                            }
                        }
                    }
                    else
                    {
                        sHtmlControls += "<select id=\"" + sComID + "\" name =\"" + sComID + "\"> ";
                        sHtmlControls += "<option value=\"\"></option>";              //第一行为空，即未选中
                        if ((dtSelected != null) && ((sFatherValue == null) || (sFatherValue.Length <= 0)))  //一般下拉显示数据 
                        {
                            for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                            {
                                sHtmlControls += "<option value=\"" + dtSelected.Rows[i][dtId].ToString() + "\" ";
                                if (dtSelected.Rows[i][dtId].ToString() == sValue)
                                    sHtmlControls += " selected=\"selected\" ";
                                sHtmlControls += ">" + /*dtSelected.Rows[i][dtId].ToString() + " " +*/ dtSelected.Rows[i][dtName].ToString() + "</option>";
                            }
                        }
                        else if ((dtSelected != null) && (sFatherValue != null) && (sFatherValue.Length > 0))//特殊子级时显示数据，有父子级关系的子级显示数据
                        {
                            for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                            {
                                if (dtSelected.Rows[i]["Father_PropertyValue"].ToString().Equals(sFatherValue))
                                {
                                    sHtmlControls += "<option value=\"" + dtSelected.Rows[i][dtId].ToString() + "\" ";
                                    if (dtSelected.Rows[i][dtId].ToString() == sValue)
                                        sHtmlControls += " selected=\"selected\" ";
                                    sHtmlControls += ">" + /*dtSelected.Rows[i][dtId].ToString() + " " + */dtSelected.Rows[i][dtName].ToString() + "</option>";
                                }
                            }
                        }
                        else                                                                                // 直接显示某条显示数据
                        {
                            sHtmlControls += "<option value=\"\" ";
                            sHtmlControls += "></option>";
                        }
                        sHtmlControls += "</select>";
                    }
                    break;
                }
            case (int)EnumHelper.E_ColDataType.COL_FDDL://多级下拉框实现 aiks 20090927
                {
                    string strFValue = string.Empty;
                    string strChldValue = string.Empty;
                    string sAllChldValue = string.Empty;
                    string strFName = string.Empty;
                    string strChldName = string.Empty;
                    string sAllChldName = string.Empty;
                    string strTemp = string.Empty;
                    string fid = "Father_PropertyValue";
                    string fname = "TypeName";
                    string dtTableName = dtSelected.TableName;
                    string sChildControls = dtTableName.Substring(dtTableName.IndexOf("-") + 1, dtTableName.Length - dtTableName.IndexOf("-") - 1);
                    sChildControls = "Cls-" + sChildControls + "-"+(int)(EnumHelper.E_ColDataType.COL_DDL);
                    for (int i = 0; i <= dtSelected.Rows.Count - 1; ++i)
                    {
                        if (dtSelected.Rows[i][fid].ToString() != strFValue)
                        {
                            if (strFValue != "")
                            {
                                sAllChldValue += strFValue + strChldValue + ";";
                                sAllChldName += strFValue + strChldName + ";";
                                strChldValue = "";
                                strChldName = "";
                            }
                            strFValue = dtSelected.Rows[i][fid].ToString();
                            strTemp += "<option value=\"" + strFValue + "\" ";
                            if (strFValue == sValue)
                                strTemp += " selected=\"selected\" ";
                            strTemp += ">" + /*strFValue + " " +*/ dtSelected.Rows[i][fname].ToString() + "</option>";
                            strChldValue += "-" + dtSelected.Rows[i][dtId].ToString();
                            strChldName += "-" + dtSelected.Rows[i][dtName].ToString();
                        }
                        else
                        {
                            strChldValue += "-" + dtSelected.Rows[i][dtId].ToString();
                            strChldName += "-" + dtSelected.Rows[i][dtName].ToString();
                        }
                    }

                    sAllChldValue += strFValue + strChldValue + ";";
                    sAllChldName += strFValue + strChldName + ";";
                    sHtmlControls += "<select id=\"" + sComID + "\" name =\"" + sComID + "\" OnChange=\"SelectTheSecond(this,'" + sChildControls
                                        + "','" + sAllChldValue + "')\"> ";//,'" + sAllChldName + "'

                    //第一行为空，即未选中
                    sHtmlControls += "<option value=\"\"></option>";
                    sHtmlControls += strTemp;
                    sHtmlControls += "</select>";
                    sHtmlControls += "<input id=\"Child" + sChildControls + "\" name =\"Child" + sChildControls + "\" "
                                        + " type=\"hidden\" value=\"" + sAllChldName + "\" />";
                    break;
                }
            default:
                {
                    sHtmlControls += "<input id=\"" + sComID + "\" name =\"" + sComID + "\" "
                                    + " type=\"text\" runat=\"server\" value=\"" + sValue + "\" ";
                    if (bRead)
                        sHtmlControls += "readonly=\"readonly\" ";
                    sHtmlControls += "/>";
                    break;
                }
        }

        sHtmlControls += sConTypeE;
        return sHtmlControls;
    }


    public string DisPlayFilesPath(int iType,int iIndex,Boolean dbFile,string sFileID,string sFileName,string sFilePath,string FileDocument,string documentpath)
    {
        //int iPos = 0;
        string sHtmlControls = "";
        string sUrl = "";
        string sPicUrl = "";
        switch (iType)
        {
            case (int)EnumHelper.E_ColDataType.COL_IMAGE:
                {
                    sUrl = sFilePath.Replace('\\','/');
                    sPicUrl = sFilePath;
                    sHtmlControls = "<tr id='SignItem"+iIndex+"'><td>";
                    sHtmlControls += iIndex+ "</td><td>";
                    sHtmlControls += "<a href='javascript:;' onclick=\"ShowPicInfo('" + sUrl + "')\">" + sFileName + "</a>";
                    sHtmlControls += "<input name='file_SignItem" + iIndex + "' type='hidden' id='file_SignItem" + iIndex + "'";
                    if (dbFile)
                    {
                        sHtmlControls += " value=\"" + sFileID + "\" ";
                    }
                        sHtmlControls += "/>";
                    sHtmlControls += "</td><td>";
                    sHtmlControls += "<img  style=\"width:30px; height:30px\" src=\"" + sPicUrl + "\" id =\"img" + sFileID + "\" />";
                    sHtmlControls += "</td><td>";
                    sHtmlControls += "<div align='center' style='width:40px'><a href='javascript:;' onclick=\"DeleteSignRow('SignItem" + iIndex 
                                + "')\">删除</a></div>";
                    sHtmlControls += "</td></tr>";
                    break;
                }
            default:
                {
                    sHtmlControls = "<tr><td>";
                    sHtmlControls +=  sFileName +
                        "<input name='file" + sFileID + "' type='hidden' id='file" + sFileID + "' />";
                    sHtmlControls += "</td><td>";
                    sHtmlControls += "";//"<img  style=\"width:30px; height:30px\" src=\"" + sFilePath + "\" id =\"img" + sFileID + "\" />";
                    sHtmlControls += "</td></tr>";
                    break;
                }
        }
        return sHtmlControls;
    }

    /*
     * 1——整型Integer，
     * 2——浮点型Float，
     * 3——字符型String，
     * 4——布尔Bool，
     * 5——Date，
     * 6——time， 
     * 7——Binary/Image
     */

    public string GetDateControl(string title, string ctlName, string ctlValue, string type, string fg)
    {//fg=    s:表示起止时间，e 为截止时间
        string flag = type;
        string html = "<li>"
                    + title
                    + "<input name='" + fg + "My_Control_" + ctlName + "_" + flag + "' value='" + ctlValue + "' style='width:100px' onfocus='setday(this)' size='9' maxlength='10'>"
                    + "</li>";
        return html;
    }

    public string GetTextBoxControl(string title, string ctlName, string ctlValue, string type, string sysFunction)
    {
        string flag = type;
        string id = "My_Control_" + ctlName + "_" + flag;
        string temp = title;
        if (title.Length > 7)//超过7个字的情况
        {
            string alltitle = title;
            title = title.Substring(0, 6) + "...";
            string html = "<li><a title='"+temp+"'>"
                        + title
                        + "<input name='My_Control_" + ctlName + "_" + flag + "' value='" + ctlValue + "' " + (sysFunction != "" ? "readOnly='true'" : "") + " style='width:100px' onchange='this.className=this.value;'  size='9'>"
                        + (sysFunction != "" ? GetButtonOpenSysFun(sysFunction, id) : "")
                        + "</li>";
            return html;
        }
        else
        {
             string html = "<li><a>"
                        + title
                        + "<input name='My_Control_" + ctlName + "_" + flag + "' value='" + ctlValue + "' " + (sysFunction != "" ? "readOnly='true'" : "") + " style='width:100px' onchange='this.className=this.value;'  size='9'>"
                        + (sysFunction != "" ? GetButtonOpenSysFun(sysFunction, id) : "")
                        + "</li>";
             return html;
        }

        
    }

    public string GetRadioButtonControl_Sex(string ctlName, string ctlValue, string type)
    {
        string flag = type;
        string sex = (ctlValue.Equals("男") ? "1" : "0");
        string html = "<li>"
                        + "性别:男<input name='My_Control_" + ctlName + "_" + flag + "' " + (sex == "1" ? "checked" : "") + "  type='radio'>"
                        + "女<input name='My_Control_" + ctlName + "_" + flag + "' " + (sex == "0" ? "checked" : "") + "  type='radio'>"
                    + "</li>";
        return html;
    }

    public string GetSelectControl(string title, string ctlName, DataTable dt, string type)
    {
        if (dt == null)
        {
            return "";
        }
        Dictionary<string, string> dic = new Dictionary<string, string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dic.Add(dt.Rows[i]["0"].ToString(), dt.Rows[i]["1"].ToString());
        }

        return GetSelectControl(title, ctlName, dic, type, false, "", false);
    }

    public string GetSelectControl(string title, string ctlName, Dictionary<string, string> dic, string type, bool isMuti, string selectedKey, bool mustSelect)
    {
        if (dic == null)
        {
            return "";
        }
        string flag = type;
        string value = "<option value = '-1'>--请选择--</option>";
        if (mustSelect)
        {
            value = "";
        }
        string muti = "";
        if (isMuti)
        {
            muti = " multiple='multiple' ";
            value = "";
        }
        foreach (KeyValuePair<string, string> kvp in dic)
        {
            string selected = "";
            if (kvp.Key == selectedKey)
            {
                selected = " selected='selected' ";
            }
            value += "<option value='" + kvp.Key + "'" + selected + ">" + kvp.Value + "</option>";
        }
       

        string html = "<li>"
                    + title
                    + ":<select name='My_Control_" + ctlName + "_" + flag + "' " + muti + " style='width:100px' >"
                    + value
                    + "</select>"
                    + "</li>";
        return html;
    }

    public string GetSelectControlWithDiv(string title, string ctlName, Dictionary<string, string> dic, string type, bool isMuti, string selectedKey, bool mustSelect)
    {
        if (dic == null)
        {
            return "";
        }
        string flag = type;
        string value = "<option value = '-1'>--请选择--</option>";
        if (mustSelect)
        {
            value = "";
        }
        string muti = "";
        if (isMuti)
        {
            muti = " multiple='multiple' ";
            value = "";
        }
        foreach (KeyValuePair<string, string> kvp in dic)
        {
            string selected = "";
            if (kvp.Key == selectedKey)
            {
                selected = " selected='selected' ";
            }
            value += "<option value='" + kvp.Key + "'" + selected + ">" + kvp.Value + "</option>";
        }


        string html = "<li>"
                    + title
                    + ":<div id=" + ctlName + "><select name='My_Control_" + ctlName + "_" + flag + "' " + muti + " style='width:100px' >"
                    + value
                    + "</select></div>"
                    + "</li>";
        return html;
    }

    public string GetEnterTag()
    {
        return "<br />";
    }

    public string GetButtonOpenSysFun(string functionName, string parentId)
    {
        string html = "<input type='button' value = '>>>' id = '" + parentId + "' onclick='" + functionName + ";' class='buttonface' style='width: 25px' /></a>";
        return html;
    }


    public string GetHiddenFieldControl(string ctlName, string ctlValue)
    {
        return "<input type='hidden' name='" + ctlName + "' id='" + ctlName + "' value='" + ctlValue + "'>";
    }

    public string GetCheckBox(string id,string name, string value)
    {
        return "<input " + (id.Equals("") ? "" : "id='" + id + "' ") + " " + (name.Equals("") ? "" : "name='" + name + "' ") + " type ='checkbox' value='" + value + "' />";
    }

    public string GetEmptyTypeXNotNull()
    {
        return "<font color='Red'>*</font>";
    }

    public string GetEmptyTypeXNullAndSubmit()
    {
        return "<font color='Blue'>*</font>";
    }

}
